Lab 31

Menus

CS211 Lab Policy:

Instructions:

For this lab you will modify your GUI program from Lab 30 to add standard menus and a context menu to the plotting program. Since it is complicated to rename GUI program file names, please start your assignment with these files: Lab31.fig, Lab31.m. (use right-click, save target as...)

  1. Using guide, add the following standard menus to Lab31.fig:
    1. File menu
      • Save menu item    (make the Tag property be Save)
      • Load menu item   (make the Tag property be Load)
      • separator
      • Exit menu item     (make the Tag property be Exit)
    2. Reset menu                (make the Tag property be Reset)
       
  2. Using guide, add the following context menus to Lab31.fig:
    1. Line_width_menu menu
      • Thin lines          (make the Tag property be Thin_lines)
      • Medium lines    (make the Tag property be Medium_lines)
      • Thick lines        (make the Tag property be Thick_lines)
     
  3. To speed up this lab assignment so that you will have time to work on the GR review, the code for each callback function is provided below. Copy and paste the following lines of code to each appropriate callback function. If you do not understand any of the lines you are copying, please discuss them with your instructor.
    1. Save callback function
      [FileName DirectoryName] = uiputfile('*.mat');
      if FileName ~= 0
        FileName = [DirectoryName FileName];
        Coefficients = [ get(handles.Slider_a, 'Value') ...
                         get(handles.Slider_b, 'Value')];
        save(FileName, 'Coefficients');
      end
    2. Load callback function
      [FileName DirectoryName] = uigetfile('*.mat');
      if FileName ~= 0
        FileName = [DirectoryName FileName];
        load(FileName);
        set(handles.Slider_a, 'Value', Coefficients(1));
        set(handles.Slider_b, 'Value', Coefficients(2));
        Update_plot(handles);
      end
    3. Exit callback function

      close(handles.figure1);

    4. Reset callback function
      set(handles.Slider_a, 'Value', pi);
      set(handles.Slider_b, 'Value', 0.0);
      Update_plot(handles);
    5. Thin_lines callback function
      set(handles.Line_width_menu, 'UserData', 1);
      
      Lines = get(handles.Plot_axes, 'children');
      set(Lines(1), 'LineWidth', 1);
    6. Medium_lines callback function
      set(handles.Line_width_menu, 'UserData', 3);
      
      Lines = get(handles.Plot_axes, 'children');
      set(Lines(1), 'LineWidth', 3);
    7. Thick_lines callback function
      set(handles.Line_width_menu, 'UserData', 8);
      
      Lines = get(handles.Plot_axes, 'children');
      set(Lines(1), 'LineWidth', 8);
    8. Update_plot() function (replace ALL of the existing code with this new version)
A = get(handles.Slider_a, 'Value');
B = get(handles.Slider_b, 'Value');
X = -10:0.1:10;
Line_handle = plot(handles.Plot_axes, X, cos(X+A) + sin(B*X) );
set(handles.Plot_axes, 'YLim', [-2 2]);
Line_width = get(handles.Line_width_menu, 'UserData');
set(Line_handle, 'LineWidth', Line_width);

set(handles.Title_text, 'String', ...
    ['cos(x+' num2str(A) ') + sin(' num2str(B) 'x)'] );

set(Line_handle, 'UIContextMenu', handles.Line_width_menu);
  1. Add the following line to the Lab31_openingFcn() function (before the line Update_plot(handles))

set(handles.Line_width_menu, 'UserData', 1);

Spend your remaining time working on the review for GR 2.

Turn-in:

Submit your Lab31.m and Lab31.fig files.